package 剑指offer;

public class _55平衡二叉树 {
    public boolean isBalanced(TreeNode root) {
        if(root == null){
            return true;
        }
        if(Math.abs(dep(root.left) - dep(root.right)) > 1){
            return false;
        }
        return isBalanced(root.left) && isBalanced(root.right);
    }
    public int dep(TreeNode root){
        if(root == null){
            return 0;
        }else{
            int left = dep(root.left);
            int right = dep(root.right);
            return Math.max(left,right) + 1;
        }
    }

}
